package com.bingfor.sharedemo;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Created by LY on 2017/2/27.
 */

public class ShareDialog extends Dialog {

    private LinearLayout toWeiXin;
    private LinearLayout toWeiBo;
    private LinearLayout toWeiXinQuan;
    private LinearLayout toQq;

    private onWeixinOnclickListener weiXinOnclickListener;//取消按钮被点击了的监听器
    private onWeixinQuanOnclickListener weiXinQuanOnclickListener;//确定按钮被点击了的监听器
    private onWeiBoOnclickListener weiBoOnclickListener;//取消按钮被点击了的监听器
    private onQqOnclickListener qqOnclickListener;//确定按钮被点击了的监听器

    /**
     * 设置微信
     */
    public void setweiXinOnclickListener(onWeixinOnclickListener weiXinQuanOnclickListener) {
        this.weiXinOnclickListener = weiXinQuanOnclickListener;
    }

    /**
     * 设置微信朋友圈
     */
    public void setWeixinQuanOnclickListener( onWeixinQuanOnclickListener weiXinQuanOnclickListener) {

        this.weiXinQuanOnclickListener = weiXinQuanOnclickListener;
    }
    /**
     * 设置QQ
     */
    public void setQqOnclickListener(onQqOnclickListener qqOnclickListener) {
        this.qqOnclickListener = qqOnclickListener;
    }

    /**
     * 设置微博
     */
    public void setWeiBoOnclickListener(onWeiBoOnclickListener weiBoOnclickListener) {

        this.weiBoOnclickListener = weiBoOnclickListener;
    }

    public ShareDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.share_dialog_layout);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);

        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();

    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        //设置微信朋友
        toWeiXin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (weiXinOnclickListener != null) {
                    weiXinOnclickListener.onYesClick();
                }
            }
        });
        //设置微信朋友圈
        toWeiXinQuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (weiXinQuanOnclickListener != null) {
                    weiXinQuanOnclickListener.onYesClick();
                }
            }
        });
        //设置微博
        toWeiBo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (weiBoOnclickListener != null) {
                    weiBoOnclickListener.onYesClick();
                }
            }
        });
        //设置QQ
        toQq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (qqOnclickListener != null) {
                    qqOnclickListener.onYesClick();
                }
            }
        });
    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData(){

    }

    /**
     * 初始化界面控件
     */
    private void initView(){
        toWeiXin = (LinearLayout) findViewById(R.id.toWeiXin);
        toWeiBo = (LinearLayout) findViewById(R.id.toWeiBo);
        toWeiXinQuan = (LinearLayout) findViewById(R.id.toWeiXinQuan);
        toQq = (LinearLayout) findViewById(R.id.toQq);
    }

    /**
     * 从外界Activity为Dialog设置标题
     *
     * @param title
     */
    public void setTitle(String title){

    }

    /**
     * 从外界Activity为Dialog设置dialog的message
     *
     * @param message
     */
    public void setMessage(String message) {

    }

    /**
     * 设置确定按钮和取消被点击的接口
     */
    public interface onWeixinOnclickListener {
        public void onYesClick();
    }

    public interface onWeixinQuanOnclickListener {
        public void onYesClick();
    }

    public interface onWeiBoOnclickListener {
        public void onYesClick();
    }
    public interface onQqOnclickListener {
        public void onYesClick();
    }

}
